package com.zcp.controller;


import com.zcp.entity.Student;
import com.zcp.entity.Tag;
import com.zcp.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("tag")
public class TagController {
    @Autowired
    private TagService tagService;

    @RequestMapping("save")
    public String save(Tag tag){
        tagService.save(tag);
        return "redirect:/tag/findAll";
    }


    @RequestMapping("findAll")
    public String findAll(Model model){
        List<Tag> tags= tagService.findAll();
        model.addAttribute("tags",tags);
        return "back/tag/index";

    }

    @GetMapping("change/{id}")
    public String change(@PathVariable("id") Integer id, Model model){
        Tag tag = tagService.change(id);
        model.addAttribute("tag",tag);
        return "back/tag/change";
    }

    @RequestMapping("changed")
    public String changeed(Tag tag){
        tagService.changed(tag);
        return "redirect:/tag/findAll";
    }
    @GetMapping("delete/{id}")
    public String delete(@PathVariable("id") Integer id){
        tagService.delete(id);
        return "redirect:/tag/findAll";
    }
}
